# coding: utf-8
from datetime import datetime
from sqlalchemy import Column, String, Integer, DateTime, ForeignKey
from app.extensions import db

"""
采集策略配置表
"""
class CollectStrategyConfig(db.Model):
    __tablename__ = 'sjml_collect_config'

    id = Column(Integer, primary_key=True, autoincrement=True, comment='主键ID')
    system_id = Column(Integer, ForeignKey('system_access_config.id'), nullable=False, comment='系统接入配置ID，外键')
    collect_mode = Column(String(50), nullable=False, comment='采集方式（手动/自动）')
    collect_freq = Column(String(20), nullable=False, comment='采集频率（日/周/月）')
    collect_time = Column(String(20), comment='采集时间')
    collect_detail = Column(String(100), comment='采集具体配置（如具体到分/周几/月几）')
    create_time = Column(DateTime, default=datetime.now, nullable=False, comment='创建时间')

    def to_dict(self):
        return {
            'id': self.id,
            'system_id': self.system_id,
            'collect_mode': self.collect_mode,
            'collect_freq': self.collect_freq,
            'collect_time': self.collect_time,
            'collect_detail': self.collect_detail,
            'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S') if self.create_time else None,
        }
